﻿create proc sp_Sys_Users_InsertUpdate
	@Usercode varchar(20) = null,
	@UserPass varchar(50) = null,
	@UserID int = null,
	@UserName nvarchar(100) = null,
	@IsUse bit = null,
	@XML ntext = null
as
begin
	declare @iDoc int
	exec sp_xml_preparedocument @iDoc output, @XML
	select @UserID = UserID, @UserCode = UserCode, @UserName = UserName, @UserPass = UserPass, @IsUse = IsUse
	from openxml(@iDoc, N'/Root/Users')
	with (UserID int, UserCode varchar(20), UserName nvarchar(100), UserPass varchar(50), IsUse bit)
	exec sp_xml_removedocument @iDoc

	if @UserID = 0
	begin
		insert into Sys_Users(UserCode, UserName, UserPass, IsUse)
		values (@UserCode, @UserName, @UserPass, @IsUse)
	end
	else
	begin
		update Sys_Users
		set UserCode = @UserCode,
			UserName = @UserName,
			UserPass = @UserPass,
			IsUse = @IsUse
		where UserID = @UserID
	end	
end